package hz.mobileproject.pda.ui.activity;

import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.blankj.utilcode.util.LogUtils;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.ui.CustomVideoView;


public class VideoSplashActivity extends AppCompatActivity {

    private CustomVideoView videoview;
    private int mCurrentPosition1;
    private int mCurrentPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_video_splash);

        initView();

//        copyDatabaseFile();
//        ((MyApplication)getApplication()).initGreenDao();
    }

    private void initView() {


        videoview = (CustomVideoView) findViewById(R.id.videoview);
        //设置播放加载路径
        videoview.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.welcome_video2));
        videoview.requestFocus();
        //播放
        videoview.start();
        //循环播放
        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
                startActivity(new Intent(VideoSplashActivity.this, LoginActivity.class));
                overridePendingTransition(0,0);
                VideoSplashActivity.this.finish();
            }
        });


    }


    @Override
    protected void onStop() {
        super.onStop();
        mCurrentPosition = videoview.getCurrentPosition();
        LogUtils.e("onStop ------>" + mCurrentPosition);
    }

    @Override
    protected void onResume() {
        super.onResume();
        LogUtils.e("onResume ------>" + mCurrentPosition );

        videoview.start();
        videoview.seekTo(mCurrentPosition);
    }
}
